package com.dorm.cj;

import java.lang.reflect.Proxy;

public class ProxyMain {
    public static void main(String[] arg) {
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        TestProxy testProxy=new TestProxy();
        ProxyInterface impl=new ProxyInterfaceImpl();
//        ProxyInterface instance = (ProxyInterface)testProxy.getInstance(impl);
//        System.out.println(instance.say("hello"));

        ProxyInterface o = (ProxyInterface)Proxy.newProxyInstance(impl.getClass().getClassLoader(),
                impl.getClass().getInterfaces(),
                (proxy, method, args) -> {
                    System.out.println("proxy======");
                    return method.invoke(impl, args);
                });

        System.out.println(o.say("hello"));
    }
}
